package com.atguigu.design.pattern.v2;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @Author: shenhao
 * @CreatTime: 2024/11/8 21:05
 * @Version: 1.0
 * 对象工厂, 工厂模式
 */
public class Factory {
    //ConcurrentHashMap 线程安全的map
    private static Map<String,HandlerStrategyFactory> strategyFactories = new ConcurrentHashMap<>();
    public static HandlerStrategyFactory getStrategyFactory(String strategy) {
        return strategyFactories.get(strategy);
    }
    public static void registerStrategyFactory(String strategy, HandlerStrategyFactory strategyFactory) {
        System.out.println("strategy = " + strategy + ", strategyFactory = " + strategyFactory);
        if (null == strategy || null == strategyFactory) {
            return;
        }
        strategyFactories.put(strategy, strategyFactory);
    }
}
